package common.util.BaseZtree;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class BaseZtreeUtils {
	
	 public static List<BaseZTree> getTemplateData(List<BaseZTree> queryList){ 
		 
		 List<BaseZTree> parentList = new ArrayList<>();
		 for (BaseZTree baseZTree : queryList) { 
			 if ("0".equals(baseZTree.getpId())) { 
				 parentList.add(baseZTree); 
			}
		} 
		 recursionChildren(parentList, queryList);
		 return parentList; 
	} 
	 
	public static void recursionChildren(List<BaseZTree> parentList, List<BaseZTree> allList) {
		for (BaseZTree parentBaseZTree : parentList) {
			List<BaseZTree> childrenList = new ArrayList<>();
			for (BaseZTree baseZTree : allList) {
				if (baseZTree.getpId().equals(parentBaseZTree.getId())) {
					childrenList.add(baseZTree); 
				} 
			}
			if (childrenList.size() > 0) {
				parentBaseZTree.setChildren(childrenList);
				recursionChildren(childrenList, allList); 
			}
		}
	}
	
}
